﻿using UnityEngine;
using System.Collections;
using DG.Tweening;

public class BlueBall2 : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}

	public Director director = Director.Left;
	public float speed = 5.0f;

	// Update is called once per frame
	void Update () {
		Rigidbody2D rigidbody = this.GetComponent<Rigidbody2D> ();
		Vector2 v = new Vector2(0, 0);
		if(this.director == Director.Up){
			v.y = 1;
		}
		else if(this.director == Director.Down){
			v.y = -1;
		}
		else if(this.director == Director.Left){
			v.x = -1;
		}
		else if(this.director == Director.Right){
			v.x = 1;
		}
		rigidbody.velocity = v * speed;
	}

	public void ChangeDirector(){
		if(this.director == Director.Up) this.director = Director.Right;
		else if(this.director == Director.Right) this.director = Director.Down;
		else if(this.director == Director.Down) this.director = Director.Left;
		else if(this.director == Director.Left) this.director = Director.Up;
	
	}

	void OnCollisionEnter2D(Collision2D c){
		if (c.gameObject.tag == "Player") {
			MapMaster.Instance.KillPlayer();
		} else {
			ChangeDirector ();
		}
	}

}
 